#include "LayoutPage.h"  
namespace MircoUi{ 
    class BatteryItem: public vItem{
    private:
        int8 level;        // 电池电量等级(-50-150%)
        uint8 charging;    // 充电状态，0=未充电，1=充电中        
    public:
        virtual sVec2 draw(sVec2 ap);         
        // 设置电池电量
        void setLevel(int8 batteryLevel) {
            if (batteryLevel > 100) batteryLevel = 100;
            if (level != batteryLevel) {
                level = batteryLevel;
                changed();
            }
        }        
        // 设置充电状态
        void setCharging(bool isCharging) {
            uint8 newState = isCharging ? 1 : 0;
            if (charging != newState) {
                charging = newState;
                changed();
            }
        }
        // 获取当前电量
        int8 getLevel() {
            return level;
        }        
        // 获取充电状态
        bool isCharging() {
            return charging == 1;
        }
    };
}

